package com.mcc.framework.config;

import com.mcc.common.config.ProjectConfig;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfig {

    @Value("${knife4j.enable}")
    private Boolean enable;

    /**
     * 系统基础配置
     */
    @Autowired
    private ProjectConfig projectConfig;

    @Bean
    public Docket defaultApi() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .enable(enable)
                .apiInfo(new ApiInfoBuilder()
                        //.title("标题：MCC脚手架_接口文档")
                        //.description("无")
                        // 作者信息
                        .contact(new Contact(projectConfig.getAuthor(), null, null))
                        // 版本
                        .version("版本号:" + projectConfig.getVersion())
                        .build())
                .select()
                //这里指定Controller扫描包路径
                .apis(CustomRequestHandlerSelectors.withClassAnnotation(Api.class))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }

    @Bean
    public Docket customApi() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .enable(enable)
                .apiInfo(new ApiInfoBuilder()
                        .contact(new Contact(projectConfig.getAuthor(), null, null))
                        // 版本
                        .version("版本号:" + projectConfig.getVersion())
                        .build())
                //分组名称
                .groupName("custom")
                .select()
                //这里指定Controller扫描包路径
                .apis(CustomRequestHandlerSelectors.basePackage("com.mcc.design"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
}
